package com.example.hudongwx.myclass0719application;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.example.hudongwx.myclass0719application.fragment.FragLogin;
import com.example.hudongwx.myclass0719application.fragment.FragRegister;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

@ContentView(R.layout.activity_user)
public class UserActivity extends AppCompatActivity {
    @ViewInject(R.id.user_imageview_back)
    private ImageView  imageView;
    @ViewInject(R.id.user_tablayout)
    private TabLayout tabLayout;
    @ViewInject(R.id.user_viewpager)
    ViewPager  viewPager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
   //将tablayout与viewpage绑定
           tabLayout.setupWithViewPager(viewPager);
        Myadpter  myadpter=new Myadpter(getSupportFragmentManager());
        viewPager.setAdapter(myadpter);



    }
    @Event(R.id.user_imageview_back)
    private void goback(View v){
         finish();
    }
        class Myadpter extends FragmentPagerAdapter{


            public Myadpter(FragmentManager fm) {
                super(fm);
            }

            @Override
            public Fragment getItem(int position) {
                if (0==position){
                    return new FragLogin();
                }else {
                    return new FragRegister();
                }
            }

            @Override
            public int getCount() {
                return 2;
            }

            @Override
            public CharSequence getPageTitle(int position) {
                if (position==0){
                    return "注册";
                }else {
                    return "登陆";
                }
            }
        }

}
